This invention relates to the use of a magnetic field to apply a time-varying force to a force-sensing cantilever in an atomic force microscope in order to enhance the imaging sensitivity of the microscope through a scheme of synchronous detection of the corresponding modulation in the cantilever deflection signal. The cantilever may be coated with a magnetic material in which case the force may be applied either as a result of the torque induced by a magnetic field on a permanently magnetized cantilever or as the result of the force on a permanent or induced magnetic moment that arises from gradients in the applied field.